inscription: Add ::wrap-mode
authorBenjamin Otte <otte@redhat.com>
Sun, 12 Jun 2022 00:58:22 +0000 (02:58 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 12 Jun 2022 01:10:50 +0000 (03:10 +0200)
We use a different wrap-mode than GtkLabel, because we cannot just
resize the widget to make long words fit, we have to fit the size we are
given.

gtk/gtkinscription.c
gtk/gtkinscription.h

index 6a2260027ac6e8a1e72b0ac97534abab1045e21e..c8937df9e9e417e51ff597bb17bf2c2d3fb09bb1 100644 (file)
@@ -86,6 +86,7 @@ enum
   PROP_NAT_LINES,
   PROP_TEXT,
   PROP_TEXT_OVERFLOW,
+  PROP_WRAP_MODE,
   PROP_XALIGN,
   PROP_YALIGN,
 
@@ -154,6 +155,10 @@ gtk_inscription_get_property (GObject    *object,
       g_value_set_enum (value, self->overflow);
       break;
 
+    case PROP_WRAP_MODE:
+      g_value_set_enum (value, pango_layout_get_wrap (self->layout));
+      break;
+
     case PROP_XALIGN:
       g_value_set_float (value, self->xalign);
       break;
@@ -210,6 +215,10 @@ gtk_inscription_set_property (GObject      *object,
       gtk_inscription_set_text_overflow (self, g_value_get_enum (value));
       break;
 
+    case PROP_WRAP_MODE:
+      gtk_inscription_set_wrap_mode (self, g_value_get_enum (value));
+      break;
+
     case PROP_XALIGN:
       gtk_inscription_set_xalign (self, g_value_get_float (value));
       break;
@@ -626,6 +635,21 @@ gtk_inscription_class_init (GtkInscriptionClass *klass)
                        GTK_INSCRIPTION_OVERFLOW_CLIP,
                        G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+  /**
+   * GtkInscription:wrap-mode: (attributes org.gtk.Property.get=gtk_inscription_get_wrap_mode org.gtk.Property.set=gtk_inscription_set_wrap_mode)
+   *
+   * Controls how the line wrapping is done.
+   *
+   * Note that unlike `GtkLabel`, the default here is %PANGO_WRAP_WORD_CHAR.
+   *
+   * Since: 4.8
+   */
+  properties[PROP_WRAP_MODE] =
+      g_param_spec_enum ("wrap-mode", NULL, NULL,
+                         PANGO_TYPE_WRAP_MODE,
+                         PANGO_WRAP_WORD_CHAR,
+                         G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
   /**
    * GtkInscription:xalign: (attributes org.gtk.Property.get=gtk_inscription_get_xalign org.gtk.Property.set=gtk_inscription_set_xalign)
    *
@@ -1152,6 +1176,51 @@ gtk_inscription_get_text_overflow (GtkInscription *self)
   return self->overflow;
 }
 
+/**
+ * gtk_inscription_set_wrap_mode: (attributes org.gtk.Method.set_property=wrap-mode)
+ * @self: a `GtkInscription`
+ * @wrap_mode: the line wrapping mode
+ *
+ * Controls how line wrapping is done.
+ *
+ * Since:4.8
+ */
+void
+gtk_inscription_set_wrap_mode (GtkInscription *self,
+                               PangoWrapMode   wrap_mode)
+{
+  g_return_if_fail (GTK_IS_INSCRIPTION (self));
+
+  if (pango_layout_get_wrap (self->layout) == wrap_mode)
+    return;
+
+  pango_layout_set_wrap (self->layout, wrap_mode);
+
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WRAP_MODE]);
+}
+
+/**
+ * gtk_inscription_get_wrap_mode: (attributes org.gtk.Method.get_property=wrap-mode)
+ * @self: a `GtkInscription`
+ *
+ * Returns line wrap mode used by the inscription.
+ *
+ * See [method@Gtk.Inscription.set_wrap_mode].
+ *
+ * Returns: the line wrap mode
+ *
+ * Since:4.8
+ */
+PangoWrapMode
+gtk_inscription_get_wrap_mode (GtkInscription *self)
+{
+  g_return_val_if_fail (GTK_IS_INSCRIPTION (self), PANGO_WRAP_WORD_CHAR);
+
+  return pango_layout_get_wrap (self->layout);
+}
+
 /**
  * gtk_inscription_set_markup: (attributes org.gtk.Method.set_property=markup)
  * @self: a `GtkInscription`
index af53a7917dfa2aa6385e607976b81bf0cfcc751a..41b2738fd87fd3b7e4c8a96abe52519530efe7d0 100644 (file)
@@ -71,6 +71,11 @@ GtkInscriptionOverflow  gtk_inscription_get_text_overflow       (GtkInscription
 GDK_AVAILABLE_IN_4_8
 void                    gtk_inscription_set_text_overflow       (GtkInscription         *self,
                                                                  GtkInscriptionOverflow  overflow);
+GDK_AVAILABLE_IN_4_8
+PangoWrapMode           gtk_inscription_get_wrap_mode           (GtkInscription         *self);
+GDK_AVAILABLE_IN_4_8
+void                    gtk_inscription_set_wrap_mode           (GtkInscription         *self,
+                                                                 PangoWrapMode           wrap_mode);
 
 GDK_AVAILABLE_IN_4_8
 guint                   gtk_inscription_get_min_chars           (GtkInscription         *self);